package com.cci.kangdao.controller;

import com.cci.kangdao.service.CSUHealthStatusService;
import com.cci.kangdao.service.CSURemoteUpgradeService;
import com.cci.kangdao.utilTool.ParameterTool;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@Controller
public class CSUServiceController {

    /** 1、日志 */
    private static final Logger LOG = Logger.getLogger(CRMPlatformController.class);


    @Autowired
    private CSUHealthStatusService healthStatusService;

    @Autowired
    private CSURemoteUpgradeService remoteUpgradeService;

    @RequestMapping(value="/getNeedUpgradeVehicles.aspx")
    public ModelAndView getNeedUpgradeVehiclesList(HttpServletRequest request,
                                     HttpServletResponse response) {
        try{
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("response", response);
            map.put("request", request);
            return remoteUpgradeService.getVehicleUpgradeStatus(map);
        }catch(Exception ex){
            LOG.error(ex.getMessage(),ex);

            String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
            ParameterTool.writeResponse(response, msg);
        }
        return null;
    }

    @RequestMapping(value="/getUpgradeHistoryVehicles.aspx")
    public ModelAndView getUpgradeHistoryVehiclesList(HttpServletRequest request,
                                                         HttpServletResponse response) {
        try{
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("response", response);
            map.put("request", request);
            return remoteUpgradeService.getUpgradeHistory(map);
        }catch(Exception ex){
            LOG.error(ex.getMessage(),ex);

            String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
            ParameterTool.writeResponse(response, msg);
        }
        return null;
    }

    @RequestMapping(value="/getVehiclesHealthInfos.aspx")
    public ModelAndView getVehiclesHealthInfos(HttpServletRequest request,
                                                            HttpServletResponse response) {
        try{
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("response", response);
            map.put("request", request);
            return healthStatusService.getVehiclesHealthInfos(map);
        }catch(Exception ex){
            LOG.error(ex.getMessage(),ex);

            String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
            ParameterTool.writeResponse(response, msg);
        }
        return null;
    }
    @RequestMapping(value="/getTotalNeedUpgradeVehicles.aspx")
    public ModelAndView getTotalNeedUpgradeVehicles(HttpServletRequest request,
                                               HttpServletResponse response) {
        try{
            Map<String, Object> map = ParameterTool.getParameterRequest(request, true);
            map.put("response", response);
            map.put("request", request);
            return remoteUpgradeService.getTotalNeedUpgradeVehicles(map);
        }catch(Exception ex){
            LOG.error(ex.getMessage(),ex);

            String msg = "{\"status\": -99,\"msg\": \"未知错误\"}";
            ParameterTool.writeResponse(response, msg);
        }
        return null;
    }
}
